package net.shao.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import net.shao.R;

/**
 * Created by shao on 2016/6/29.
 */
public class HeadBar extends RelativeLayout {

    //    @ViewInject(R.id.tv_Title)
    private TextView tv_Title;
    //    @ViewInject(R.id.tv_LeftText)
    private TextView tv_leftText;
    //    @ViewInject(R.id.tv_RightText)
    private TextView tv_RightText;

    public interface OnRightClickListener {
        void OnRightClickListener(View view);
    }

    public interface OnLeftClickListener{
        void onLeftClickListener(View view);
    }

    public HeadBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public HeadBar(Context context) {
        super(context);
        initView(context);
    }

    private OnRightClickListener onRightClickListener;

    private OnLeftClickListener onLeftClickListener;

    public void setOnRightClickListener(OnRightClickListener onRightClickListener) {
        this.onRightClickListener = onRightClickListener;
    }

    public void setOnLeftClickListener(OnLeftClickListener onLeftClickListener) {
        this.onLeftClickListener = onLeftClickListener;
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.titie_view, this);
        tv_leftText = (TextView) view.findViewById(R.id.tv_LeftText);
        tv_Title = (TextView) view.findViewById(R.id.tv_Title);
        tv_RightText = (TextView) view.findViewById(R.id.tv_RightText);

        tv_RightText.setOnClickListener(v -> {
            if (onRightClickListener != null) {
                onRightClickListener.OnRightClickListener(v);
            }
        });

        tv_leftText.setOnClickListener(v -> {
            if (onLeftClickListener != null){
                onLeftClickListener.onLeftClickListener(v);
            }
        });
    }

    public void setTitle(String title) {
        tv_Title.setVisibility(VISIBLE);
        tv_Title.setText(title);
    }

    public void setLeftText(String leftText){
        tv_leftText.setVisibility(VISIBLE);
        tv_leftText.setText(leftText);
    }

    public void setRightText(String rightText) {
       tv_RightText.setVisibility(VISIBLE);
        tv_RightText.setText(rightText);
    }


}
